package ee.ut.cs.mc.madp.p2pdivider.task;

import android.os.AsyncTask;
import android.util.Log;
import ee.ut.cs.mc.madp.p2pdivider.networking.DividerServer;

/**
 * @author Kaarel Jõgeva
 *
 */
public class ReceiveGreetingsTask extends AsyncTask<Void, Void, Void> {

    public static final String TAG = ReceiveGreetingsTask.class.getCanonicalName();
    private final DividerServer server;

    public ReceiveGreetingsTask(DividerServer server) {
        this.server = server;
    }

    @Override
    protected Void doInBackground(Void... params) {
        Log.i(TAG, "Waiting for greetings...");
        server.start();
        // Hold the connection open until we get the new IP
        while (true) {
            if (isCancelled()) {
                break;
            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }

        return null;
    }
}